package cn.sciento.transfer.infra.datasource.factory;

import javax.sql.DataSource;
import cn.sciento.transfer.infra.datasource.properties.BasicDataSourceProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.util.Assert;

public class DataSourceFactory {
  private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceFactory.class);
  
  public static DataSource createDataSource(BasicDataSourceProperties basicDataSourceProperties) {
    Assert.notNull(basicDataSourceProperties, "basic data source properties cannot be null.");
    basicDataSourceProperties.validate();
    DataSource dataSource = DataSourceBuilder.create().type(basicDataSourceProperties.buildType()).driverClassName(basicDataSourceProperties.getDriverClassName()).url(basicDataSourceProperties.getUrl()).username(basicDataSourceProperties.getUsername()).password(basicDataSourceProperties.getPassword()).build();
    basicDataSourceProperties.bindProperties(dataSource);
    return dataSource;
  }
  
  public static DataSource getDataSource(Long dataSourceId, String serviceName) {
    return null;
  }
}
